package com.ruoyi.sys.security.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sys.security.domain.TbPatrollingPlan;
import com.ruoyi.sys.security.service.ITbPatrollingPlanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 巡更计划Controller
 * 
 * @author iuxin
 * @date 2022-05-25
 */
@RestController
@RequestMapping("/electronicPatrolling/plan")
public class TbPatrollingPlanController extends BaseController
{
    @Autowired
    private ITbPatrollingPlanService tbPatrollingPlanService;

    /**
     * 查询巡更计划列表
     */
    @PreAuthorize("@ss.hasPermi('electronicPatrolling:plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbPatrollingPlan tbPatrollingPlan)
    {
        startPage();
        List<TbPatrollingPlan> list = tbPatrollingPlanService.selectTbPatrollingPlanList(tbPatrollingPlan);
        return getDataTable(list);
    }

    /**
     * 导出巡更计划列表
     */
    @PreAuthorize("@ss.hasPermi('electronicPatrolling:plan:export')")
    @Log(title = "巡更计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbPatrollingPlan tbPatrollingPlan)
    {
        List<TbPatrollingPlan> list = tbPatrollingPlanService.selectTbPatrollingPlanList(tbPatrollingPlan);
        ExcelUtil<TbPatrollingPlan> util = new ExcelUtil<TbPatrollingPlan>(TbPatrollingPlan.class);
        util.exportExcel(response, list, "巡更计划数据");
    }

    /**
     * 获取巡更计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('electronicPatrolling:plan:query')")
    @GetMapping(value = "/{ppId}")
    public AjaxResult getInfo(@PathVariable("ppId") Long ppId)
    {
        return AjaxResult.success(tbPatrollingPlanService.selectTbPatrollingPlanByPpId(ppId));
    }

    /**
     * 新增巡更计划
     */
    @PreAuthorize("@ss.hasPermi('electronicPatrolling:plan:add')")
    @Log(title = "巡更计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbPatrollingPlan tbPatrollingPlan)
    {
        return toAjax(tbPatrollingPlanService.insertTbPatrollingPlan(tbPatrollingPlan));
    }

    /**
     * 修改巡更计划
     */
    @PreAuthorize("@ss.hasPermi('electronicPatrolling:plan:edit')")
    @Log(title = "巡更计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbPatrollingPlan tbPatrollingPlan)
    {
        return toAjax(tbPatrollingPlanService.updateTbPatrollingPlan(tbPatrollingPlan));
    }

    /**
     * 删除巡更计划
     */
    @PreAuthorize("@ss.hasPermi('electronicPatrolling:plan:remove')")
    @Log(title = "巡更计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ppIds}")
    public AjaxResult remove(@PathVariable Long[] ppIds)
    {
        return toAjax(tbPatrollingPlanService.deleteTbPatrollingPlanByPpIds(ppIds));
    }
}
